{extend name="common/adminBase" /}
{block name="body"}
<body>
<style>
    .r{
        float: right;
    }
</style>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                     <a class="layui-btn " onclick="xadmin.open('添加证书','addzs',800,600)"><i class="layui-icon"></i>添加</a>
                </div>
                {if $data}
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>证书名称</th>
                            <th>创建时间</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {volist name="data" id="v"}
                        <tr>
                            <td>{$v.id}</td>
                            <td>{$v.title}</td>
                            <td>{$v.time|date='Y-m-d H:i:s'}</td>
                            <td>
                                {if $v.status == 1}
                                <input type="checkbox" name="switch" value="{$v.id}" lay-skin="switch" lay-filter="switchTest"  checked >
                                {else/}
                                <input type="checkbox" name="switch" value="{$v.id}" lay-skin="switch" lay-filter="switchTest" >
                                {/if}
                            </td>
                            <td class="td-manage">
                                <a class="layui-btn" href="javascript:void(0)" onclick="del({$v.id})">删除</a>
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">
                        <div>
                        
                        </div>
                    </div>
                </div>
                {else/}
                    <div style="width:100%;font-size:18px;text-align:center;">目前没有添加额外证书</div>
                {/if}
            </div>
        </div>
    </div>
</div>

</iframe>

</body>
<script>
    function del(id){
        layer.confirm('确认要删除吗？', {
            btn : [ '确定', '取消' ]//按钮
        }, function(index) {
            $.ajax({
                        url:"/index/center/delzs",
                        data:{id:id},
                        type:'post',
                        dataType:'json',
                        success:function (res) {
                            if (res.code==1){
                                location.href='';
                            }else{
                                layer.alert(res.msg,function (index) {
                                    layer.close(index);
                                })
                            }
                        }
                    })
        }); 
    }
    

    layui.use('form', function(){
        var  form = layui.form;
        form.on('switch(switchTest)', function (data) {
            console.log(data.elem.checked); //开关是否开启，true或者false
            console.log(data.value); //开关value值，也可以通过data.elem.value得到
            $.ajax({
                url:"/index/center/changezsStatus",
                data:{id:data.value,status:data.elem.checked},
                type:'post',
                dataType: 'json',
                success:function (res) {
                    if (res.status ==1){
                        layer.msg(res.msg,{icon:1,time:1500},function () {
                            location.reload();
                        });
                    }else{
                        layer.alert(res.msg,function (index) {
                            layer.close(index);
                        })
                    }
                }
            })


            return false;
        });
    });


</script>

{/block}